/**
 * centent header create to by doujiabao
 */

import React, { Component } from 'react'
import { connect } from 'react-redux'

import Cookie from 'js-cookie'

import styles from './index.module.styl'

import { Avatar, Popconfirm } from 'antd'

class Header extends Component {

    outlogin = () => {
        Cookie.remove('d_logintoken')
        //...
        setTimeout(() => {
            window.location.reload()
        }, 300)
    }

    render() {
        const {
            userInfo
        } = this.props

        return (<div className={styles.header}>
            <Popconfirm
                placement="bottomLeft"
                title={'退出登录？'}
                okText="确认"
                cancelText="取消"
                onConfirm={this.outlogin}
            >
                <Avatar className={styles.uesrAvatar} src={userInfo.userAvatar} />
            </Popconfirm>
        </div>)
    }

}

const mapStateToProps = (state) => {
    return {
        userInfo: state.userInfo
    }
}

export default connect(mapStateToProps, null)(Header)